package hgx.spring.cloud.lession.myhystrix.test;/**
 * Created by liujun on 2018/4/19.
 */

import java.util.List;

import hgx.spring.cloud.lession.myhystrix.MyCommandKeyType;
import hgx.spring.cloud.lession.myhystrix.MyRequest;
import hgx.spring.cloud.lession.myhystrix.MyRequestHystrixCommand;
import hgx.spring.cloud.lession.productrepertory.dao.ProductDaoImpl;
import hgx.spring.cloud.lession.productrepertory.vo.ProductVo;

/**
 * @author Administrator
 * @create 2018-04-19 14:39
 */
public class MyController {

    private MyRequestHystrixCommand myRequestHystrixCommand;

    public MyController() {
        this.myRequestHystrixCommand = new MyRequestHystrixCommand(new MyRequest(new ProductDaoImpl()));
    }

    public List<ProductVo> queryProducts() {
        System.out.println("--------------开始调用  queryProducts()");
        List<ProductVo> list = (List<ProductVo>) myRequestHystrixCommand.handler(null, MyCommandKeyType.Query_Products);
        System.out.println("==============结束调用  queryProducts()");
        return list;
    }

    public ProductVo getProductById(Long id) {
        System.out.println("--------------开始调用  getProductById()");
        ProductVo productVo = (ProductVo) myRequestHystrixCommand.handler(new Long[]{id}, MyCommandKeyType.Get_Product);
        System.out.println("==============结束调用  getProductById()");
        return productVo;
    }

    public boolean createProducts(ProductVo productVo) {
        System.out.println("--------------开始调用  createProducts()");

        boolean flag = (boolean) myRequestHystrixCommand.handler(new ProductVo[]{productVo}, MyCommandKeyType.Create_Product);
        System.out.println("==============结束调用  createProducts()");
        return flag;
    }

}
